/*
 * Tree.h
 *
 *  Created on: May 21, 2011
 *      Author: trungtq
 */

#ifndef TREE_H_
#define TREE_H_

#include "Node.h"
#include "OutLabel.h"

class Tree {
private:
    Node* root;
    NodeSet nodes;

public:
    Tree();
    Tree(Node* root);
    Tree(Node* root, NodeSet nodes);
    virtual ~Tree();

public:
    Node* getRoot() const;
    NodeSet getNodes() const;
    bool setNewRoot(Node* newRoot);
    void insertNode(Node* node);
    bool insertNode(Node* child, Node* parent);
    bool insertNode(Node* child, Node* parent, OutLabel* label);
    bool validate();
    int size();
    void clear();
    void print();
};

class TreeCompare {
public:
    bool operator() (Tree* tree1, Tree* tree2) {
        Node* root1 = tree1->getRoot();
        Node* root2 = tree2->getRoot();
        return (root1 < root2);
    }
};

typedef set<Tree*, TreeCompare> TreeSet;

#endif /* TREE_H_ */
